#!/user/bin/python
#coding = utf-8

import sys 
import re
lists = []
listmap = []
person = '1'
friend = []
#summarize the friends of a person
for line in sys.stdin:
    words = line.split('\t')
    words[0] = re.sub('[^\d]+','',words[0])
    words[1] = re.sub('[^\d]+','',words[1])
    if person == words[0]:
        friend.append(words[1])
    else:
        item = friend[0]
        friend[0] = person
        friend.append(item)
        listmap.append(friend)
        person = words[0]
        friend = [words[1]]

item = friend[0]
friend[0] = person
friend.append(item)
listmap.append(friend)

# for line in list :
#     if line[0]=='189':
#         print(line)


for line in listmap:
    left = 0
    person = line[0]
    while left < len(line) - 1:
        if left == 0:
            right = 1
            while right < len(line):
                print(line[left]+','+line[right]+'#'+'0')
                right +=1
        else:
            right = left + 1
            while right < len(line):
                print(line[left]+','+line[right]+'#'+person)
                print(line[right]+','+line[left]+'#'+person)

                right +=1
        left +=1